package hjslm.Controller.Background;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import hjslm.Bean.NavcustomBean;
import hjslm.Common.Impl.CommonFunImpl;
import hjslm.Service.INavCustomService;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import framework.base.common.Pager;
import framework.base.controller.BaseController;

@Controller
@RequestMapping("/b_navcustom")
public class NavCustomController extends BaseController{

	/**
	 * 自动导航页面
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	INavCustomService navCustomService;

	@Override
	public void setLogger() {
	}
	
	@RequestMapping("/index")
	public ModelAndView index(NavcustomBean bean, Pager<NavcustomBean> pager){
		ModelAndView modelAndView  = new ModelAndView("background/navcustom/index");
		pager = navCustomService.selectPage(bean, pager);
		modelAndView.addObject("pager", pager);
		return modelAndView;
	}
	
	@RequestMapping("/add")
	public ModelAndView add(){
		ModelAndView modelAndView = new ModelAndView("background/navcustom/add");
		return modelAndView;
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(NavcustomBean bean){
		ModelAndView modelAndView = new ModelAndView("background/navcustom/edit");
		bean = navCustomService.selectOne(bean);
		modelAndView.addObject("bean", bean);
		return modelAndView;
	}
	
	@RequestMapping("/insert")
	public void insert(NavcustomBean bean,HttpServletResponse response){
		bean.setId(CommonFunImpl.uuid("N"));
		bean.setInserttime(CommonFunImpl.currentTime(1));
		int retVal = navCustomService.insert(bean);
		// 返回值
		try {
			PrintWriter out = response.getWriter();
			out.print(retVal);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	@RequestMapping("/update")
	public void update(NavcustomBean bean,HttpServletResponse response){
		bean.setInserttime(CommonFunImpl.currentTime(1));
		int retVal = navCustomService.update(bean);
		// 返回值
		try {
			PrintWriter out = response.getWriter();
			out.print(retVal);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	@RequestMapping("/delete")
	public void Delete(NavcustomBean bean, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		int ret = navCustomService.delete(bean);
		try {
			PrintWriter out = response.getWriter();
			out.print(ret);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
